package com.doge;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class DogeButtonMenu extends Actor implements InputProcessor
{
	int x;
	int y;
	SpriteBatch batch = new SpriteBatch();
	Main parent;
	int activeButton;
	String statusText;
	public BitmapFont font = new BitmapFont();
	ArrayList<DogeButton> buttons = new ArrayList<DogeButton>();
	
	DogeButtonMenu(int x, int y, Main parent)
	{
		this.x = x;
		this.y = y;
		
		this.parent = parent;
	}
	
	boolean addButton(DogeButton a)
	{
		return buttons.add(a);
	}
	
	boolean removeButton(DogeButton a)
	{
		if(buttons.remove(a)) return true;
		else 				  return false;
	}
	
	void draw()
	{
		batch.begin();
		batch.draw(Textures.outline, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		font.draw(batch, statusText, Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/3);
		
		for(int x = 0; x < buttons.size(); ++x)
		{
			//float padding = 20;
			float xpos = x;//Gdx.graphics.getWidth()/2;
			float ypos = (15*x)+font.getXHeight()+y;//(Gdx.graphics.getHeight()/2);
			String name = buttons.get(x).name;
			
			//draw arrow
			if(x == activeButton)
			{
				batch.draw(parent.textures.arrowRight,xpos-70, 
						ypos-10, 
						64, 
						36);
			}
			
			//draw 'buttons'
			font.setColor(Color.WHITE);
			
			font.draw(batch, name, xpos, ypos+15);
		}
		batch.end();
	}
	
	public boolean keyUp(int keycode) 
	{	
		switch(keycode)
		{
		case Keys.W:
			if(++activeButton > buttons.size()-1 )
				activeButton = 0;
			return true;
		case Keys.S:
			if(--activeButton < 0 )
				activeButton = buttons.size()-1;
			return true;
		case Keys.ENTER:
			buttons.get(activeButton).callback();
			return true;
		}
		
        return false;
    }

	@Override
	public boolean keyDown(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		return false;
	}
}
